package com.nhjf.dao.finetTalk;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.nhjf.dao.BaseDao;
import com.nhjf.model.finetTalk.FinetTalkComment;
import com.nhjf.pojo.qo.finetTalk.FinetTalkCommentQo;

@Repository
public class FinetTalkCommentDao extends BaseDao<FinetTalkComment, FinetTalkCommentQo>{

	@Override
	protected Criteria buildCriteria(Criteria criteria, FinetTalkCommentQo qo) {
		// TODO Auto-generated method stub
		if(qo!=null) {	
			criteria.setFetchMode("user", qo.isSeachUser()?FetchMode.JOIN:FetchMode.SELECT);	
			if(qo.getFinetTalkId()!=null) {
				criteria.add(Restrictions.eq("finetTalkId",qo.getFinetTalkId()));
			}
			if(qo.getUserId()!=null) {
				criteria.add(Restrictions.eq("user.id",qo.getUserId()));
			}
			if(qo.getCommentTime()!=null) {
				criteria.add(Restrictions.eq("commentTime",qo.getCommentTime()));
			}
			if(qo.getCommentType()!=null) {
				criteria.add(Restrictions.eq("commentType",qo.getCommentType()));
			}
			if(qo.getCommentUserType()!=null) {
				criteria.add(Restrictions.eq("commentUserType",qo.getCommentUserType()));
			}
			 criteria.addOrder(Order.desc("commentTime"));
		}
		return criteria;
	}

	@Override
	protected Class<FinetTalkComment> getEntityClass() {
		// TODO Auto-generated method stub
		return FinetTalkComment.class;
	}

}
